package com.zhou.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zhou.dao.CheckGroupMapper;
import com.zhou.dao.MapDao;
import com.zhou.entity.PageResult;
import com.zhou.entity.QueryPageBean;
import com.zhou.pojo.Address;
import com.zhou.pojo.CheckGroup;
import com.zhou.service.MapService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 地图管理
 */
@Service(interfaceClass = MapService.class)
@Transactional
public class MapServiceImpl implements MapService {
    //注入DAO对象
    @Autowired
    private MapDao mapDao;

    /**
     * 检查项分页查询
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);
        //忽略空格查询条件
        if (queryPageBean.getQueryString() != null && queryPageBean.getQueryString().length() > 0) {
            queryString = queryPageBean.getQueryString().trim();// 去除查询条件首尾空格
        }
        Page<Address> page = mapDao.findByCondition(queryString);
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 删除地址
     *
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        mapDao.deleteById(id);
    }

    /**
     * 添加地址
     *
     * @param address
     */
    @Override
    public void add(Address address) {
        mapDao.add(address);
    }

    /**
     * 获取公司地址的详细信息
     *
     * @return
     */
    @Override
    public List<Address> getAddressDetail() {
        return mapDao.findAddressAll();
    }

    /**
     * 获取所有地址的名称
     *
     * @return
     */
    @Override
    public List<String> getAddressNames() {
        return mapDao.getAddressNames();
    }
}
